/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.com.transportes.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import pe.com.transportes.modelo.Gastobus;

/**
 *
 * @author z3phiroth
 */
public class GastosbusDAO {

      public void insertargastobus(Connection con,Gastobus c) throws SQLException{

    String sql ="insert into gastosbus values (?,?,?,?,?,?)";
    PreparedStatement ps = con.prepareStatement(sql);


    System.out.println("codigo dao "+ c.getCod_gasto());

    ps.setInt(1,c.getCod_gasto());
        ps.setString(2,c.getCod_bus());
        ps.setString(3, c.getDescripcion());
        ps.setString(4,c.getLugar());
         ps.setDouble(5,c.getCosto());
       ps.setString(6, c.getFecha());

    ps.executeUpdate();
    }
public ArrayList<Gastobus> listagastobusxdia(Connection con,String fecha) throws SQLException{

  String sql = "select * from gastosbus where fecha=?";
ArrayList<Gastobus> lista = new ArrayList<Gastobus>();
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setString(1,fecha);

          ResultSet rs = ps.executeQuery();
        while(rs.next()){
   Gastobus bean = new Gastobus();
            bean.setCod_gasto(rs.getInt(1));
              bean.setCod_bus(rs.getString(2));
            bean.setDescripcion(rs.getString(3));
            bean.setLugar(rs.getString(4));
            bean.setCosto(rs.getDouble(5));
            bean.setFecha(rs.getString(6));

             lista.add(bean);
        }
        return lista;


}


 public ArrayList<Gastobus> Listagastobusxmes(Connection con,String fecha) throws SQLException{

          ArrayList<Gastobus> lista = new ArrayList<Gastobus>();

  String sql = "select * from gastosbus where fecha=?";
        PreparedStatement ps = con.prepareStatement(sql);
          ResultSet rs = ps.executeQuery();
       while(rs.next()){
     Gastobus bean = new Gastobus();
        bean.setCod_gasto(rs.getInt(1));
              bean.setCod_bus(rs.getString(2));
            bean.setDescripcion(rs.getString(3));
            bean.setLugar(rs.getString(4));
            bean.setCosto(rs.getDouble(5));
            bean.setFecha(rs.getString(6));

            lista.add(bean);
    
        }
        return lista;

}











}
